﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy3_5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // 1. 读取本次行驶公里数
                double currentDistance = double.Parse(txtDistance.Text);

                // 2. 实例化CountDistance对象
                CountDistance cd = new CountDistance();
                cd.Distance = currentDistance;

                // 3. 计算总里程（调用实例方法，累加静态总里程）
                cd.CalculateTotal();

                // 4. 显示总里程结果
                MessageBox.Show($"您的汽车已行驶{CountDistance.TotalDistance}公里", "里程计算", MessageBoxButtons.OK, MessageBoxIcon.Information);

                // 5. 清空输入框
                txtDistance.Clear();
            }
            catch (FormatException)
            {
                MessageBox.Show("输入格式不合法，请输入有效数字！", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
